

package com.loong.loong.hik.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.loong.loong.common.core.util.R;
import com.loong.loong.common.log.annotation.SysLog;
import com.loong.loong.hik.entity.CdcAlarm;
import com.loong.loong.hik.service.CdcAlarmService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.loong.loong.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 疾控告警
 *
 * @author cs
 * @date 2023-04-13 17:00:47
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/cdcalarm" )
@Api(value = "cdcalarm", tags = "疾控告警管理")
public class CdcAlarmController {

    private final  CdcAlarmService cdcAlarmService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param cdcAlarm 疾控告警
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_view')" )
    public R getCdcAlarmPage(Page page, CdcAlarm cdcAlarm) {
        return R.ok(cdcAlarmService.page(page, Wrappers.query(cdcAlarm)));
    }


    /**
     * 通过id查询疾控告警
     * @param alarmId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{alarmId}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_view')" )
    public R getById(@PathVariable("alarmId" ) Integer alarmId) {
        return R.ok(cdcAlarmService.getById(alarmId));
    }

    /**
     * 新增疾控告警
     * @param cdcAlarm 疾控告警
     * @return R
     */
    @ApiOperation(value = "新增疾控告警", notes = "新增疾控告警")
    @SysLog("新增疾控告警" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_add')" )
    public R save(@RequestBody CdcAlarm cdcAlarm) {
        return R.ok(cdcAlarmService.save(cdcAlarm));
    }

    /**
     * 修改疾控告警
     * @param cdcAlarm 疾控告警
     * @return R
     */
    @ApiOperation(value = "修改疾控告警", notes = "修改疾控告警")
    @SysLog("修改疾控告警" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_edit')" )
    public R updateById(@RequestBody CdcAlarm cdcAlarm) {
        return R.ok(cdcAlarmService.updateById(cdcAlarm));
    }

    /**
     * 通过id删除疾控告警
     * @param alarmId id
     * @return R
     */
    @ApiOperation(value = "通过id删除疾控告警", notes = "通过id删除疾控告警")
    @SysLog("通过id删除疾控告警" )
    @DeleteMapping("/{alarmId}" )
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_del')" )
    public R removeById(@PathVariable Integer alarmId) {
        return R.ok(cdcAlarmService.removeById(alarmId));
    }


    /**
     * 导出excel 表格
     * @param cdcAlarm 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('hik_cdcalarm_export')" )
    public List<CdcAlarm> export(CdcAlarm cdcAlarm) {
        return cdcAlarmService.list(Wrappers.query(cdcAlarm));
    }
}
